package com.iris.live.services.common.kpi;

import java.util.HashMap;
import java.util.Map;

/**
 * KPI工具类
 */
public class KPIUtils {
    private static KPIUtils kpiUtils = new KPIUtils();
    protected Map<String, KPIMetaData> cnToEn = new HashMap<>();

    public static KPIUtils getInstance() {
        return kpiUtils;
    }

    private void buildKPIs() {
        cnToEn.put("BMBS销售目标完成率", new KPIMetaData()
                .setType(2)
                .setNumerator("manufacturer_vehicle_sale_volumn")
                .setNumeratorMemo("新车销量")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setDenominator("manufacturer_sale_target")
                .setDenominatorMemo("bmbs_销售目标")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("LSH销售目标完成率", new KPIMetaData()
                .setType(2)
                .setNumerator("vehicle_sale_volumn")
                .setNumeratorMemo("新车销量")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setDenominator("dealer_sale_target")
                .setDenominatorMemo("lsh_销售目标")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("本地上牌率", new KPIMetaData()
                .setType(2)
                .setNumerator("license_num")
                .setNumeratorMemo("本地上牌的新车台数")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setDenominator("vehicle_sale_volumn")
                .setDenominatorMemo("零售数")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("销售订单完成率", new KPIMetaData()
                .setType(2)
                .setNumerator("new_order_num")
                .setNumeratorMemo("新增订单数")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setDenominator("dealer_sale_target")
                .setDenominatorMemo("lsh_销售目标")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("订单池比例", new KPIMetaData()
                .setType(2)
                .setNumerator("order_num")
                .setNumeratorMemo("订单数")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setDenominator("dealer_sale_target")
                .setDenominatorMemo("lsh_销售目标")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("当月预计可开票订单池比例", new KPIMetaData()
                .setType(2)
                .setNumerator("invoicable_order_num")
                .setNumeratorMemo("可开票订单数")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setDenominator("dealer_sale_target")
                .setDenominatorMemo("lsh_销售目标")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("销售目标与新增展厅客流比", new KPIMetaData()
                .setType(2)
                .setNumerator("dealer_sale_target")
                .setNumeratorMemo("lsh_销售目标")
                .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                .setDenominator("inroom_clue_num")
                .setDenominatorMemo("进店线索数")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("新增线索进店转化率", new KPIMetaData()
                .setType(2)
                .setNumerator("first_enter_undefeated_clue_num")
                .setNumeratorMemo("首次进店且未战败的线索数")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setDenominator("new_clue_num")
                .setDenominatorMemo("新增线索数")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("未关闭线索的再次进店转化率", new KPIMetaData()
                .setType(2)
                .setNumerator("reenter_undefeated_clue_num")
                .setNumeratorMemo("再次进店且未战败的线索数")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setDenominator("new_clue_num")
                .setDenominatorMemo("新增线索数")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("客户重新分配比例", new KPIMetaData()
                .setType(2)
                .setNumerator("reassign_clue_num")
                .setNumeratorMemo("重新分配线索数")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setDenominator("inroom_times")
                .setDenominatorMemo("进店次数")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

            cnToEn.put("试乘试驾率", new KPIMetaData()
                .setType(2)
                .setNumerator("test_drive_num")
                .setNumeratorMemo("试乘试驾数")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setDenominator("inroom_clue_num")
                .setDenominatorMemo("进店线索数")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("报价率", new KPIMetaData()
                .setType(2)
                .setNumerator("quotation_num")
                .setNumeratorMemo("报价数")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setDenominator("inroom_clue_num")
                .setDenominatorMemo("进店线索数")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("订单转化率", new KPIMetaData()
                .setType(2)
                .setNumerator("order_num")
                .setNumeratorMemo("订单数")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setDenominator("inroom_clue_num")
                .setDenominatorMemo("进店线索数")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("成交率", new KPIMetaData()
                .setType(2)
                .setNumerator("vehicle_sale_volumn")
                .setNumeratorMemo("新车销量")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setDenominator("inroom_clue_num")
                .setDenominatorMemo("进店线索数")
                .setDenominatorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("展厅客流量LSH", new KPIMetaData()
                .setType(1)
                .setNumerator("inroom_clue_num")
                .setNumeratorMemo("进店线索数")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.INT));

        cnToEn.put("新增净订单数", new KPIMetaData()
                .setType(1)
                .setNumerator("new_order_num")
                .setNumeratorMemo("新增订单数")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.INT));

        cnToEn.put("新增交车数", new KPIMetaData()
                .setType(1)
                .setNumerator("delivery_num")
                .setNumeratorMemo("交车数")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.INT));

        cnToEn.put("新增零售数", new KPIMetaData()
                .setType(1)
                .setNumerator("vehicle_sale_volumn")
                .setNumeratorMemo("新车销量")
                .setNumeratorType(KPIMetaData.TYPE.INT)
                .setResultType(KPIMetaData.TYPE.INT));

        cnToEn.put("销售毛利率GP1Percent", new KPIMetaData()
                        .setType(2)
                        .setNumerator("gp1_amount")
                        .setNumeratorMemo("gp1_amount")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("vehicle_sale_amount")
                        .setDenominatorMemo("新车外部销售收入")
                        .setDenominatorType(KPIMetaData.TYPE.DOUBLE)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("销售毛利率GP1Dot5Percent", new KPIMetaData()
                        .setType(2)
                        .setNumerator("GP1dot5_amount")
                        .setNumeratorMemo("GP1dot5_amount")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("vehicle_sale_amount")
                        .setDenominatorMemo("新车外部销售收入")
                        .setDenominatorType(KPIMetaData.TYPE.DOUBLE)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("销售毛利率GP2Percent", new KPIMetaData()
                        .setType(2)
                        .setNumerator("gp2_amount")
                        .setNumeratorMemo("gp2_amount")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("vehicle_sale_amount")
                        .setDenominatorMemo("新车外部销售收入")
                        .setDenominatorType(KPIMetaData.TYPE.DOUBLE)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("销售毛利率GP3Percent", new KPIMetaData()
                        .setType(2)
                        .setNumerator("gp3_amount")
                        .setNumeratorMemo("gp3_amount")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("vehicle_sale_amount")
                        .setDenominatorMemo("新车外部销售收入")
                        .setDenominatorType(KPIMetaData.TYPE.DOUBLE)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("销售毛利率TGP", new KPIMetaData()
                        .setType(2)
                        .setNumerator("tgp_amount")
                        .setNumeratorMemo("tgp_amount")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("vehicle_sale_gross_amount")
                        .setDenominatorMemo("销售毛收入")
                        .setDenominatorType(KPIMetaData.TYPE.DOUBLE)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("库存周转天数", new KPIMetaData()
                        .setType(3)
                        .setNumerator("stock_num * 30")
                        .setNumeratorAlias("turnover_stock_num")
                        .setNumeratorMemo("周转库存")
                        .setNumeratorType(KPIMetaData.TYPE.INT)
                        .setDenominator("average_sale_volumn")
                        .setDenominatorMemo("前三个月平均销量")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.INT)
        );

        cnToEn.put("150天以上长库龄", new KPIMetaData()
                        .setType(2)
                        .setNumerator("age_larger_150")
                        .setNumeratorMemo("150天")
                        .setNumeratorType(KPIMetaData.TYPE.INT)
                        .setDenominator("stock_num")
                        .setDenominatorMemo("总库存")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("60天以上长库龄", new KPIMetaData()
                        .setType(2)
                        .setNumerator("age_larger_60")
                        .setNumeratorMemo("60天")
                        .setNumeratorType(KPIMetaData.TYPE.INT)
                        .setDenominator("stock_num")
                        .setDenominatorMemo("总库存")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("90天以上长库龄", new KPIMetaData()
                        .setType(2)
                        .setNumerator("age_larger_90")
                        .setNumeratorMemo("90天")
                        .setNumeratorType(KPIMetaData.TYPE.INT)
                        .setDenominator("stock_num")
                        .setDenominatorMemo("总库存")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("120天以上长库龄", new KPIMetaData()
                        .setType(2)
                        .setNumerator("age_larger_120")
                        .setNumeratorMemo("120天")
                        .setNumeratorType(KPIMetaData.TYPE.INT)
                        .setDenominator("stock_num")
                        .setDenominatorMemo("总库存")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("其他业务收入毛利率不含二手车续保", new KPIMetaData()
                        .setType(2)
                        .setNumerator("other_business_gross_amount")
                        .setNumeratorMemo("其他收入")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("vehicle_sale_amount")
                        .setDenominatorMemo("新车外部销售收入")
                        .setDenominatorType(KPIMetaData.TYPE.DOUBLE)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("LSH5星延保渗透率", new KPIMetaData()
                        .setType(2)
                        .setNumerator("extended_warranty_num")
                        .setNumeratorMemo("五星延保销售台数")
                        .setNumeratorType(KPIMetaData.TYPE.INT)
                        .setDenominator("vehicle_sale_volumn")
                        .setDenominatorMemo("新车销量")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("LSH5星延保毛利率", new KPIMetaData()
                        .setType(2)
                        .setNumerator("extended_warranty_gross_amount")
                        .setNumeratorMemo("延保销售毛利")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("extended_warranty_amount")
                        .setDenominatorMemo("延保销售营业额")
                        .setDenominatorType(KPIMetaData.TYPE.DOUBLE)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("二手车评估率", new KPIMetaData()
                        .setType(2)
                        .setNumerator("used_car_estimation_num")
                        .setNumeratorMemo("二手车评估台数")
                        .setNumeratorType(KPIMetaData.TYPE.INT)
                        .setDenominator("inroom_clue_num")
                        .setDenominatorMemo("进店线索数")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("金融申请率", new KPIMetaData()
                        .setType(2)
                        .setNumerator("financial_vehicle_order_num")
                        .setNumeratorMemo("订单金融台数")
                        .setNumeratorType(KPIMetaData.TYPE.INT)
                        .setDenominator("new_order_num")
                        .setDenominatorMemo("新增订单数")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("先享后选渗透率", new KPIMetaData()
                        .setType(2)
                        .setNumerator("financial_agility_vehicle_num")
                        .setNumeratorMemo("新车Agility台数")
                        .setNumeratorType(KPIMetaData.TYPE.INT)
                        .setDenominator("vehicle_sale_volumn")
                        .setDenominatorMemo("新车销量")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("新车保险渗透率", new KPIMetaData()
                        .setType(2)
                        .setNumerator("new_insurance_vehicle_num")
                        .setNumeratorMemo("新保台数")
                        .setNumeratorType(KPIMetaData.TYPE.INT)
                        .setDenominator("vehicle_sale_volumn")
                        .setDenominatorMemo("新车销量")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("金融保险业务毛利率不含续保", new KPIMetaData()
                .setType(2)
                .setNumerator("(financial_commission_amount + financial_service_fee_amount + new_insurance_commission_amount)")
                .setNumeratorAlias("financial_insurance_amount")
                .setNumeratorMemo("金融保险费用")
                .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                .setDenominator("vehicle_sale_amount")
                .setDenominatorMemo("新车外部销售收入")
                .setDenominatorType(KPIMetaData.TYPE.DOUBLE)
                .setResultType(KPIMetaData.TYPE.DOUBLE));

        cnToEn.put("单车金融手续费收入", new KPIMetaData()
                        .setType(3)
                        .setNumerator("financial_commission_amount")
                        .setNumeratorMemo("金融手续费")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("financial_vehicle_num")
                        .setDenominatorMemo("新车金融台数")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("金融渗透率", new KPIMetaData()
                        .setType(2)
                        .setNumerator("financial_vehicle_num")
                        .setNumeratorMemo("新车金融台数")
                        .setNumeratorType(KPIMetaData.TYPE.INT)
                        .setDenominator("vehicle_sale_volumn")
                        .setDenominatorMemo("新车销量")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("单车金融服务费收入", new KPIMetaData()
                        .setType(3)
                        .setNumerator("financial_service_fee_amount")
                        .setNumeratorMemo("金融服务费")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("financial_vehicle_num")
                        .setDenominatorMemo("新车金融台数")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("单车新保手续费收入", new KPIMetaData()
                        .setType(3)
                        .setNumerator("new_insurance_commission_amount")
                        .setNumeratorMemo("保险手续费")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("new_insurance_vehicle_num")
                        .setDenominatorMemo("新保台数")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("后市场业务毛利率", new KPIMetaData()
                        .setType(2)
                        .setNumerator("after_market_business_gross_amount")
                        .setNumeratorMemo("后市场业务费用")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("vehicle_sale_amount")
                        .setDenominatorMemo("新车外部销售收入")
                        .setDenominatorType(KPIMetaData.TYPE.DOUBLE)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("后市场产品毛利率", new KPIMetaData()
                        .setType(2)
                        .setNumerator("after_market_product_gross_amount")
                        .setNumeratorMemo("后市场产品销售毛利")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("after_market_product_amount")
                        .setDenominatorMemo("后市场产品营业额")
                        .setDenominatorType(KPIMetaData.TYPE.DOUBLE)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("后市场产品单车营业额", new KPIMetaData()
                        .setType(3)
                        .setNumerator("after_market_product_amount")
                        .setNumeratorMemo("后市场产品营业额")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("vehicle_sale_volumn")
                        .setDenominatorMemo("新车销量")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );

        cnToEn.put("后市场服务费单车营业额", new KPIMetaData()
                        .setType(3)
                        .setNumerator("after_market_service_fee_income")
                        .setNumeratorMemo("后市场产品营业额")
                        .setNumeratorType(KPIMetaData.TYPE.DOUBLE)
                        .setDenominator("vehicle_sale_volumn")
                        .setDenominatorMemo("新车销量")
                        .setDenominatorType(KPIMetaData.TYPE.INT)
                        .setResultType(KPIMetaData.TYPE.DOUBLE)
        );
    }

    public KPIMetaData getCnToEn(String name) {
        this.cnToEn.clear();
        buildKPIs();
        return cnToEn.get(name);
    }
}
